import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import { {{modelName}} } from './{{feature}}.model';
import { {{modelName}}Dto } from './{{feature}}.dto';

@Injectable()
export class {{modelName}}Service {
  constructor(@InjectModel({{modelName}}) private readonly model: typeof {{modelName}}) {}

  async create(dto: {{modelName}}Dto) {
    return this.model.create(dto as any);
  }

  async findAll() {
    return this.model.findAll();
  }

  async findOne(id: number) {
    return this.model.findByPk(id);
  }

  async update(id: number, dto: {{modelName}}Dto) {
    await this.model.update(dto as any, { where: { id } });
    return this.findOne(id);
  }

  async remove(id: number) {
    return this.model.destroy({ where: { id } });
  }
}
